import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/found'
  },
  {
    path: '/login',
    component: () => import('../pages/login/login.vue')
  },
  {
    path: '/phonelogin',
    component: () => import('../pages/login/phoneLogin.vue')
  },
  {
    path: '/pwlogin',
    component: () => import('../pages/login/passwordlogin.vue')
  },
  {
    path: '/main',
    component: () => import('../pages/main/index.vue'),
    redirect: 'found',
    children: [
      // tabber
      {
        path: '/found',
        name: 'found',
        component: () => import('../pages/main/found/found.vue')
      },
      {
        path: '/search',
        component: () => import('@/pages/main/search/Search.vue'),
        redirect: '/search/hotSearch',
        children: [
          {
            path: '/search/hotSearch',
            component: () => import('@/pages/main/search/HotSearch.vue')
          },
          {
            path: '/search/searchConent',
            component: () => import('@/pages/main/search/SearchConent.vue')
          }
        ]
      },
      {
        path: '/focusin',
        name: 'focusin',
        component: () => import('../pages/main/focusin/focusin.vue')
      },
      {
        path: '/mine',
        name: 'mine',
        component: () => import('../pages/main/mine/mine.vue')
      }

      // 单独页面
      // {
      //   path: '/search/searchConent',
      //   component: () => import("@/pages/main/search/SearchConent.vue"),
      // }
    ]
  },
  //播放页
  {
    path: '/playpage',
    name: 'playpage',
    component: () => import('@/pages/main/playpage/playpage.vue')
  },
  {
    path: '/playlistDetail',
    component: () => import('@/pages/main/PlayListDetail/PlayListDetail.vue')
  }
]

const router = createRouter({
  routes,
  history: createWebHashHistory()
})

// 导航守卫
router.beforeEach((to) => {
  // console.log(to)
  if (
    to.path !== '/login' &&
    to.path !== '/pwlogin' &&
    to.path !== '/phonelogin'
  ) {
    const cookie = localStorage.getItem('cookie')
    // console.log(cookie)
    // if (!cookie) {
    //   return '/login'
    // }
  }
})

router.addRoute({
  path:"/wssb",
  component:()=>import("@/components/sb.vue")
})
export default router
